#include "material.hpp"
#include <GL/gl.h>
#include <GL/glu.h>

Material::~Material()
{
}

PhongMaterial::PhongMaterial(const Colour& kd, const Colour& ks, double shininess)
  : m_kd(kd), m_ks(ks), m_shininess(shininess)
{
}

PhongMaterial::~PhongMaterial()
{
}

void PhongMaterial::apply_gl(bool pick) const
{
  // Perform OpenGL calls necessary to set up this material.
	if(!pick){
		GLfloat mat_diffuse[] = {m_kd.R(), m_kd.G(), m_kd.B(), 1.0};
	    GLfloat mat_specular[] = {m_ks.R(), m_ks.G(), m_ks.B(), 1.0};
	    GLfloat mat_shininess[] = {m_shininess};
	    //glEnable(GL_BLEND);
	    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	    glShadeModel(GL_SMOOTH);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
	    glDisable(GL_BLEND);
	}
	else{
		GLfloat mat_diffuse[] = {m_kd.R()*0.3, m_kd.G()*0.3, m_kd.B()*0.3, 1.0};
	    GLfloat mat_specular[] = {m_ks.R(), m_ks.G(), m_ks.B(), 1.0};
	    GLfloat mat_shininess[] = {m_shininess};
	    //glEnable(GL_BLEND);
	    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	    glShadeModel(GL_SMOOTH);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
	    glDisable(GL_BLEND);	
	}
}
